<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>门诊挂号</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css}" media="all"/>
</head>

<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>查询条件</legend>
</fieldset>

<form class="layui-form" method="post" id="searchFrm">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">用户姓名:</label>
            <div class="layui-input-inline">
                <input type="text" name="name"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">&nbsp;&nbsp;&nbsp;&nbsp;</label>
            <div class="layui-input-inline">
                <button type="button" class="layui-btn layui-btn-normal  layui-icon layui-icon-search" id="doSearch">查询</button>
            </div>
        </div>
    </div>
</form>

<!-- 搜索条件结束 -->
<!-- 添加和修改的弹出层开始 -->
<div style="display: none;padding-top: 20px" id="saveOrUpdateDiv" >
    <form class="layui-form"  lay-filter="dataFrm" id="dataFrm">
        <div class="layui-form-item" style="margin-left: 0">
            <div class="layui-inline">
                <label class="layui-form-label">姓名:</label>
                <div class="layui-input-inline">
                    <input type="hidden" name="id">
                    <input type="text" name="reportName" lay-verify="required"   placeholder="请输入用户姓名" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <input type="radio" name="sex" value="nan" title="男" checked>
                    <input type="radio" name="sex" value="nv" title="女" >
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">年龄:</label>
                <div class="layui-input-inline">
                    <input type="text" name="age" lay-verify="required"   placeholder="请输入用户年龄" autocomplete="off"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">科室:</label>
                <div class="layui-input-inline">
                    <select name="departmentId" id="departmentId" lay-verify="required" lay-filter="xmFilter">
                        <option value=""></option>
                        </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">科室:</label>
                <div class="layui-input-inline">
                    <select name="registeredId" id="type" lay-verify="required" lay-filter="xmFilter">
                        <option value=""></option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">医生:</label>
                <div class="layui-input-inline">
                    <select name="doctorId" id="doctorName" lay-verify="required" lay-filter="xmFilter">
                        <option value=""></option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 0">
            <div class="layui-input-block">
                <button type="button" class="layui-btn layui-btn-normal layui-btn-sm layui-icon layui-icon-release" lay-filter="doSubmit" lay-submit="">提交</button>
                <button type="reset" class="layui-btn layui-btn-warm layui-btn-sm layui-icon layui-icon-refresh" >重置</button>
            </div>
        </div>
    </form>

</div>
<!-- 添加和修改的弹出层结束 -->
<!-- 数据表格开始 -->
<table class="layui-hide" id="userTable" lay-filter="userTable"></table>
<div style="display: none;" id="userToolBar">
    <button type="button" class="layui-btn layui-btn-sm" lay-event="add">增加</button>
</div>
<div  id="userBar" style="display: none;">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</div>
<!-- 数据表格结束 -->
<script th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:inline="none">
    var tableIns;
    layui.extend({
        dtree:'layui_ext/dist/dtree'
    }).use([ 'jquery', 'layer', 'form', 'table' ], function() {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        //渲染数据表格
        tableIns=table.render({
            elem: '#userTable'   //渲染的目标对象
            ,url:'report' //数据接口
            ,title: '用户数据表'//数据导出来的标题
            ,toolbar:"#userToolBar"   //表格的工具条
            ,height:'full-200'
            ,cellMinWidth:200 //设置列的最小默认宽度
            ,page: 1  //是否启用分页, limits: [10, 20, 30]
            ,limits: [2, 20, 30]
            ,limit: 2//默认采用3
            ,cols: [[   //列表数据
                {field:'reportId', title:'单据号',align:'center',width:"9%"}
                ,{field:'reportName', title:'姓名',align:'center',width:"9%"}
                ,{field:'sex', title:'性别',align:'center',width:"9%"}
                ,{field:'age', title:'年龄',align:'center',width:"9%"}
                ,{field:'department', title:'科室',align:'center',width:"9%"}
                ,{field:'doctorName', title:'医生',align:'center',width:"9%"}
                ,{field:'type', title:'挂号类别',align:'center',width:"9%"}
                ,{field:'price', title:'挂号费',align:'center',width:"9%"}
                ,{field:'time', title:'挂号时间',align:'center',width:"9%"}
                ,{field:'users', title:'操作员',align:'center',width:"9%"}
                ,{fixed: 'right', title:'操作', toolbar: '#userBar',align:'center',width:'9%'}
            ]]
        })
        //模糊查询
        $("#doSearch").click(function(){
            var params=$("#searchFrm").serialize();
            tableIns.reload({
                url:"selPerson?"+params
            })
        });
        //监听头部工具栏事件
        table.on("toolbar(userTable)",function(obj){
            switch(obj.event){
                case 'add':
                    add();
                    break;
            };
        })
        var url;
        var mainIndex;
        //打开添加页面
        function add(){
            mainIndex=layer.open({
                type:1,
                title:'添加用户',
                content:$("#saveOrUpdateDiv"),
                area:['400px','600px'],
                success:function(index){
                    //清空表单数据
                    $("#dataFrm")[0].reset();
                    url="addperson";
                }
            });
        }
        //打开修改页面
        function openUpdate(data){
            mainIndex=layer.open({
                type:1,
                title:'修改用户',
                content:$("#saveOrUpdateDiv"),
                area:['400px','600px'],
                success:function(index){
                    form.val("dataFrm",data);
                    url="update";
                }
            });
        }
        //保存
        form.on("submit(doSubmit)",function(obj){
            //序列化表单数据
            var params=$("#dataFrm").serialize();
            $.post(url,params,function(obj){
                layer.msg(obj);
                //关闭弹出层
                layer.close(mainIndex)
                //刷新数据 表格
                tableIns.reload();
            })
        });
        //监听行工具事件
        table.on('tool(userTable)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            if(layEvent === 'del'){ //删除
                layer.confirm('真的删除【'+data.name+'】这个用户吗', function(index){
                    //向服务端发送删除指令
                    $.post("del",{id:data.id},function(res){
                        layer.msg(res);
                        //刷新数据 表格
                        tableIns.reload();
                    })
                });
            } else if(layEvent === 'edit'){ //编辑
                openUpdate(data);
            }
        });

    })
</script>
</body>
</html>

